#include "OptionScene.h"
#include "AppDelegate.h"
#include "MainMenuScene.h"
#include "CMyGameDef.h"

using namespace cocos2d;

#define LINE_SPACE	40
#define BTN_TAG_BACK	0

CCScene* OptionScene::scene()
{
    CCScene * scene = NULL;
    do 
    {
        // 'scene' is an autorelease object
        scene = CCScene::create();
        CC_BREAK_IF(! scene);

        // 'layer' is an autorelease object
        OptionScene *layer = OptionScene::create();
        CC_BREAK_IF(! layer);

        // add layer as a child to scene
        scene->addChild(layer);
    } while (0);

    // return the scene
    return scene;
}

// on "init" you need to initialize your instance
bool OptionScene::init()
{
    bool bRet = false;
    do 
    {
        //////////////////////////////////////////////////////////////////////////
        // super init first
        //////////////////////////////////////////////////////////////////////////

        CC_BREAK_IF(! CCLayer::init());

        //////////////////////////////////////////////////////////////////////////
        // add your codes below...
        //////////////////////////////////////////////////////////////////////////
		
		CCSize size = CCDirector::sharedDirector()->getWinSize();
        // 1. Add a menu item with "X" image, which is clicked to quit the program.
		
        // Create a "close" menu item with close icon, it's an auto release object.
        CCMenuItemImage *pBackItem = CCMenuItemImage::create(
            "Images/btn_back_normal.png",
            "Images/btn_back_selected.png",
            this,
            menu_selector(OptionScene::menuCallback));
        CC_BREAK_IF(! pBackItem);

		
        // Place the menu item bottom-right conner.
		pBackItem->setTag(0);
        pBackItem->setPosition(100, size.height - 50);

        // Create a menu with the "close" menu item, it's an auto release object.
        CCMenu* pMenu = CCMenu::create(pBackItem, NULL);
        pMenu->setPosition(CCPointZero);
        CC_BREAK_IF(! pMenu);

        // Add the menu to HelloWorld layer as a child layer.
        this->addChild(pMenu, 1);
		
        bRet = true;
    } while (0);
    return bRet;
}

void OptionScene::menuCallback(CCObject* pSender)
{
	CCDirector::sharedDirector()->popScene();
}